﻿package org.hsl.avm2.translation.http;
import flash.events.HTTPStatusEvent;
import org.hsl.haxe.translation.ITranslator;
import org.hsl.haxe.translation.NativeEvent;
/**
 * A translator that translates http status events to http statusses.
 */
// Ideally, the following line would be:
// class HTTPStatusTranslator implements ITranslator<HTTPStatus> {
// However, that doesn't work targeting AVM2.
class HTTPStatusTranslator<D> implements ITranslator<D> {
	/**
	 * Creates a new http status translator.
	 */
	public function new():Void {
	}
	public function translate(nativeEvent:NativeEvent):D {
		var httpStatusEvent:HTTPStatusEvent;
		try {
			httpStatusEvent = cast(nativeEvent, HTTPStatusEvent);
		} catch (error:Dynamic) {
			throw "The nativeEvent argument must be a HTTPStatusEvent.";
		}
		return untyped new HTTPStatus(httpStatusEvent.status);
	}
}